﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Xml;
using MJHDataService;

/// <summary>
/// Summary description for MeasurementManager
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class MeasurementManager : System.Web.Services.WebService
{

    [WebMethod]
    public XmlDocument GetMeasurementUnits(int measurementUnitID)
    {
        XmlDocument xDoc = new XmlDocument();
        using (Measurement oMeasurement = new Measurement())
        {
            Hashtable oParam = new Hashtable();
            oParam.Add("MeasurementUnitID", measurementUnitID);
            using (DataTable dt = oMeasurement.GetMeasurementUnits(oParam))
            {
                Int32 nMax = Convert.ToInt32((object)dt.Compute("max(Level)", ""));
                using (DataSet ds = DataSetUtility.TransformFlatToHierarchy(dt, nMax, "MeasurementUnitID", "ParentMeasurementUnitID"))
                {
                    ds.DataSetName = "MeasurementUnitList";
                    xDoc.LoadXml(ds.GetXml());
                }
            }
        }
        return xDoc;
    }
}

